import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

// import { h } from 'vue';
import { DictEnum } from '@vben/constants';
// import { getPopupContainer } from '@vben/utils';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  // {
  //   label: '企业名称',
  //   fieldName: 'companyId',
  //   component: 'CompanySearchSelect',
  //   help: '输入企业名称后将从企业数据库中模糊查询',
  //   componentProps: {
  //     modelName: 'id',
  //     showAdd: false,
  //   },
  // },
  {
    component: 'Input',
    fieldName: 'name',
    label: '姓名',
  },
  {
    component: 'Select',
    fieldName: 'departmentId',
    componentProps: {
      options: getDictOptions(DictEnum.AUDIENCE_DEPARTMENT, true),
    },
    label: '部门',
  },
  {
    component: 'Select',
    fieldName: 'positionId',
    componentProps: {
      options: getDictOptions(DictEnum.AUDIENCE_POSITION, true),
    },
    label: '职位',
  },
  {
    component: 'PersonalTagSelect',
    fieldName: 'labelIds',
    label: '人员标签',
    defaultValue: [],
  },
];

export const userSchema: FormSchemaGetter = () => [
  {
    label: '人员ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Input',
    fieldName: 'name',
    label: '姓名',
    rules: 'required',
  },
  {
    label: '企业名称',
    fieldName: 'companyId',
    component: 'CompanySearchSelect',
    // help: '输入企业名称后将从企业数据库中模糊查询',
    componentProps: {
      showTycButton: true,
    },
    rules: 'required',
  },
  {
    label: '手机号',
    fieldName: 'mobile',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
    // rules: 'mobileRequired',
  },
  {
    label: '邮箱',
    fieldName: 'email',
    component: 'Input',
    // rules: 'emailRequired',
  },
  {
    component: 'Input',
    fieldName: 'wechatNo',
    label: '微信号',
  },
  {
    component: 'Select',
    fieldName: 'departmentId',
    componentProps: {
      options: getDictOptions(DictEnum.AUDIENCE_DEPARTMENT, true),
    },
    label: '部门',
    // rules: 'selectRequired',
  },
  {
    component: 'Select',
    fieldName: 'positionId',
    componentProps: {
      options: getDictOptions(DictEnum.AUDIENCE_POSITION, true),
    },
    label: '职位',
    // rules: 'selectRequired',
  },
  {
    component: 'AddressCascader',
    fieldName: 'addressMap',
    label: '所在地区',
    defaultValue: [],
    componentProps: {
      allowClear: false,
    },
    // rules: 'selectRequired',
  },
  {
    label: '详细地址',
    fieldName: 'address',
    component: 'Input',
  },
  {
    component: 'PersonalTagSelect',
    fieldName: 'labelIds',
    label: '人员标签',
    defaultValue: [],
    help: '可多选，通过筛选批量设置人员标签',
  },
];

export const contactResultSchema: FormSchemaGetter = () => [
  {
    label: '联络结果',
    fieldName: 'contactResult',
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.CONTACT_RESULT),
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
  {
    label: '联络详情',
    fieldName: 'contactDetail',
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: [],
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
  {
    component: 'Select',
    fieldName: 'businessProgress',
    componentProps: {
      options: getDictOptions(DictEnum.BUSINESS_PROGRESS, true),
    },
    label: '业务进度',
  },
  {
    label: '联络备注',
    fieldName: 'remark',
    component: 'Textarea',
    componentProps: {
      showCount: true,
      maxlength: 200,
      placeholder: '请输入对本次通话的总结',
      autoSize: { minRows: 6 },
    },
  },
];

export const smsSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'employeeId',
    label: '人员ID',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Input',
    fieldName: 'name',
    label: '姓名',
  },
  {
    component: 'SmsTemplateSelect',
    fieldName: 'smsTemplateId',
    label: '短信模板',
    componentProps: {
      multiple: false,
      all: false,
      options: [],
    },
    rules: 'selectRequired',
  },
];

export const emailSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'employeeId',
    label: '人员ID',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Input',
    fieldName: 'name',
    label: '姓名',
  },
  {
    component: 'Input',
    fieldName: 'email',
    label: '邮箱',
    rules: 'emailRequired',
  },
  {
    component: 'EmailTemplateSelect',
    fieldName: 'emailTemplateId',
    label: '邮件模板',
    componentProps: {
      multiple: false,
      all: false,
      allowClear: true,
      options: [],
    },
    rules: 'selectRequired',
  },
];

export const contactHistoryColumns: VxeGridProps['columns'] = [
  {
    title: '联络人',
    field: 'createByName',
    width: 150,
  },
  {
    title: '联络结果',
    field: 'contactResult',
    width: 260,
    // slots: { default: 'contactResult' },
    slots: {
      default: ({ row }) => {
        return (
          <div class="flex flex-wrap justify-center gap-2">
            {renderDict(row.contactResult, DictEnum.CONTACT_RESULT, true)}
            {renderDict(row.contactDetail, row.contactResult, true)}
          </div>
        );
      },
    },
  },
  {
    title: '业务进度',
    field: 'type',
    width: 120,
    slots: {
      default: ({ row }) => {
        return renderDict(
          row.businessProgress,
          DictEnum.BUSINESS_PROGRESS,
          true,
        );
      },
    },
  },
  {
    title: '联络备注',
    field: 'remark',
    // visible: false,
    minWidth: 150,
  },
  {
    title: '联络时间',
    field: 'createTime',
    width: 180,
  },
];
